package cn.stylefeng.guns.modular.testselect.controller;

import cn.stylefeng.guns.modular.system.warpper.DeptWarpper;
//import cn.stylefeng.guns.modular.testselect.wrapper.SellectWarpper;
import cn.stylefeng.roses.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import cn.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import cn.stylefeng.guns.modular.system.model.Select;
import cn.stylefeng.guns.modular.testselect.service.ISelectService;

import java.util.List;

/**
 * 下拉框存数据测试控制器
 *
 * @author fengshuonan
 * @Date 2018-12-12 21:58:51
 */
@Controller
@RequestMapping("/select")
public class SelectController extends BaseController {

    private String PREFIX = "/testselect/select/";

    @Autowired
    private ISelectService selectService;

    /**
     * 跳转到下拉框存数据测试首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "select.html";
    }

    /**
     * 跳转到添加下拉框存数据测试
     */
    @RequestMapping("/select_add")
    public String selectAdd() {
        return PREFIX + "select_add.html";
    }

    /**
     * 跳转到修改下拉框存数据测试
     */
    @RequestMapping("/select_update/{selectId}")
    public String selectUpdate(@PathVariable Integer selectId, Model model) {
        Select select = selectService.selectById(selectId);
        model.addAttribute("item",select);
        LogObjectHolder.me().set(select);
        return PREFIX + "select_edit.html";
    }

    /**
     * 获取下拉框存数据测试列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        List<Select> list = selectService.selectList(null);
        return list;
    }

    /**
     * 新增下拉框存数据测试
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Select select) {
        selectService.insert(select);
        return SUCCESS_TIP;
    }

    /**
     * 删除下拉框存数据测试
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer selectId) {
        selectService.deleteById(selectId);
        return SUCCESS_TIP;
    }

    /**
     * 修改下拉框存数据测试
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Select select) {
        selectService.updateById(select);
        return SUCCESS_TIP;
    }

    /**
     * 下拉框存数据测试详情
     */
    @RequestMapping(value = "/detail/{selectId}")
    @ResponseBody
    public Object detail(@PathVariable("selectId") Integer selectId) {
        return selectService.selectById(selectId);
    }
}
